<?php

namespace app\admin\model;

use think\Model;


class Bus extends Model
{

    

    

    // 表名
    protected $name = 'bus';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];
    

    







    public function lines()
    {
        return $this->belongsTo('Lines', 'lines_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public static function initTime($row)
    {
        $lines=Lines::get($row->lines_id);
        $timeTable=json_decode($lines->timetable,true);
        $len=count($timeTable);
        $diff_time=strtotime($timeTable[$len-1]['arrival_time'])-strtotime($timeTable[0]['arrival_time']);
        $row->end_time=date('H:i',strtotime($row->start_time)+$diff_time);
        $row->save();
    }
}
